#include <ESP8266WiFi.h>
#include <WiFiClientSecure.h>
#include <ArduinoJson.h>


const char* ssid = "RedmiK30";
const char* password = "q1w2e3r4";

void setup() {
  Serial.begin(9600);
  Serial.println();
  Serial.print("connecting to ");
  Serial.println(ssid);
  WiFi.begin(ssid, password); // 连接WIFI
  while (WiFi.status() != WL_CONNECTED) {
    delay(500);
    Serial.print(".");
  }
  Serial.println("");
  Serial.println("WiFi connected");
  Serial.println("IP address: ");
  Serial.println(WiFi.localIP()); // 显示WIFI地址

}

void loop() {
  Serial.println("loop ......");
  // 重点1：DynamicJsonDocument对象
  const size_t capacity = JSON_ARRAY_SIZE(1) + JSON_OBJECT_SIZE(3) + 255;
  DynamicJsonDocument doc(capacity);

  // 重点2：即将解析的json文件
  String json = "{\"code\":0,\"message\":null,\"data\":\"test\"}";

  // 重点3：反序列化数据
  deserializeJson(doc, json);


  int code = doc["code"].as<int>();
  String message = doc["message"].as<String>();
  String data = doc["data"].as<String>();

  // 通过串口监视器输出解析后的数据信息
  Serial.print("code = ");
  Serial.println(code);
  Serial.print("message = ");
  Serial.println(message);
  Serial.print("data = ");
  Serial.println(data);
  delay(3000);
}
